package com.caineng.zhaobiao.zbapi.utils;


import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 操作消息提醒
 *
 * @author ruoyi
 */
@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "统一返回", description = "返回对象")
public class AjaxResult<T> implements Serializable {

    public static final String OK_CODE = "200";


    @ApiModelProperty(value = "返回错误代码", example = "200")
    private String code = OK_CODE;

    @ApiModelProperty(value = "返回错误信息描述", example = "success")
    private String msg = "success";

    @ApiModelProperty(value = "返回对象数据", example = "返回对象数据")
    private T data = null;

    //总页数
    private int totalPages ;

    public AjaxResult(String msg, T data){
        this.msg = msg;
        this.data = data;
    }

    public static AjaxResult success(String msg){
        AjaxResult vo = new AjaxResult<>();
        vo.setMsg(msg);
        vo.setCode("200");
        return vo;
    }
    public static AjaxResult success(Object data){
        AjaxResult vo = new AjaxResult<>("success",data);
        vo.setCode("200");
        return vo;
    }

    public static AjaxResult success(String msg, Object data){
        AjaxResult vo = new AjaxResult<>(msg,data);
        vo.setCode("200");
        return vo;
    }

    public static AjaxResult success(String msg, Object data,int totalPages){
        AjaxResult vo = new AjaxResult<>(msg,data);
        vo.setCode("200");
        vo.setTotalPages(totalPages);
        return vo;
    }

    public static AjaxResult error(String msg, Object data){
        AjaxResult vo = new AjaxResult<>(msg,data);
        vo.setCode("500");
        return vo;
    }

    public static AjaxResult error(String msg){
        AjaxResult vo = new AjaxResult<>(msg,null);
        vo.setCode("500");
        return vo;
    }

    /**
     * 超过了今日查看的最大条数
     * @param msg
     * @return
     */
    public static AjaxResult maxLimitByDay(String msg){
        AjaxResult vo = new AjaxResult<>(msg,null);
        vo.setCode("440");
        return vo;
    }

    /**
     * 超过了今日访问次数
     * @param msg
     * @return
     */
    public static AjaxResult maxByDay(String msg){
        AjaxResult vo = new AjaxResult<>(msg,null);
        vo.setCode("442");
        return vo;
    }

    /**
     * 请登录
     * @param msg
     * @return
     */
    public static AjaxResult noLogin(String msg) {
        AjaxResult vo = new AjaxResult<>(msg,null);
        vo.setCode("401");
        return vo;
    }
}
